﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Web.Mvc;
using System.Web.Security;
using SmartParking.Data.Entities;
using ADEVSO.Util;
using SmartParking.Bussiness;
using System.ComponentModel;
using System.Web;

namespace SmartParking.Web.Mobile.Models
{
    public class ParkingsModel
    {
        public List<ParkingModel> Parkings { get; set; }

        public CustomerModel Customer { get; set; }

        public ParkingsModel(int customerId = 0)
        {
            Customer cust = ParkingManager.GetCustomer(customerId);

            Customer = new CustomerModel() { Address = cust.Address, CustomerID = cust.CustomerID, Email = cust.Email, Name = cust.Name, Phone = cust.Phone };
            Parkings = ParkingModel.LoadParkings(customerId);
        }
    }

    public class ParkingModel
    {
        [Required]
        [Display(Name = "Parqueo")]
        public int ParkingID { get; set; }

        [Required]
        [Display(Name = "Nombre")]
        public string Name { get; set; }

        [Required]
        [Display(Name = "Customer")]
        public int CustomerID { get; set; }

        [Required]
        [Display(Name = "Cedula Juridica")]
        [DataType(DataType.Text)]
        public string LegalId { get; set; }

        [Required]
        [Display(Name = "Razon Social")]
        [DataType(DataType.Text)]
        public string LegalName { get; set; }

        [Required]
        [Display(Name = "Cuenta Bancaria")]
        [DataType(DataType.Text)]
        public string BankAccount { get; set; }

        [Required]
        [Display(Name = "Telefono")]
        [DataType(DataType.PhoneNumber)]
        public string PhoneNumber { get; set; }

        [Required]
        [Display(Name = "Address")]
        [DataType(DataType.Text)]
        public string Address { get; set; }

        public static List<ParkingModel> LoadParkings(int customerId)
        {
            List<ParkingModel> Parkings = new List<ParkingModel>();

            foreach (var park in ParkingManager.GetParkings(customerId))
            {
                Parkings.Add(new ParkingModel() { Address = park.Address, BankAccount = park.BankAccountNumber, CustomerID = park.CustomerID, LegalId = park.LegalID, LegalName = park.LegalName, Name = park.Name, ParkingID = park.ParkingID, PhoneNumber = park.Phone });
            }

            return Parkings;
        }
    }
}
